package com.personal.common.util;

import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.UUID;

/**
 * 生成唯一键标识
 * 
 * @author linzhengjie
 * 
 */
@SuppressWarnings("unused")
public class UUIDGenerator {

	/** This Format for format the data to special format. */
	private final static Format dateFormat = new SimpleDateFormat("yyMMddHHmmssS");

	public static String getUUid() {
		UUID uuid = UUID.randomUUID();
		String id = uuid.toString().replaceAll("-", "");
		return Utils.joinString(id.substring(0, 8), id.substring(9, 13), id.substring(14, 18), id.substring(19, 23),
				id.substring(24));
	}

	/**
	 * 生成时间的随机数 规则为年月日时分秒毫秒+3位随机数
	 * 
	 * @return
	 */
	public static String getTimeId() {
		String x = getTwoRandom();
		return Utils.joinString(DateUtil.getCurrentDateTimeSSS(), "-", x);
	}

	public static String getTwoRandom() {
		String x = String.valueOf((int) (Math.random() * 100));
		if (x.length() == 1) {
			x = getTwoRandom();
		}
		return x;

	}
}
